package demo1;

class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
    public int compareTo (Student o){
        return this.age-o.age;
    }
}
public class Test {

    /**
     * 使用冒泡排序 模拟实现
     */
    public static void mySort(Comparable[] comparable){//用形参comparable接收实参student发生了向上转型
        for (int i = 0; i < comparable.length-1; i++) {
            for (int j = 0; j < comparable.length-1-i; j++) {
                if(comparable[j].compareTo(comparable[j+1])>0){
                    Comparable tmp=comparable[j];
                    comparable[j]=comparable[j+1];
                    comparable[j+1]=tmp;
                }
            }
        }
    }

    public static void main(String[] args) {
/*        Student[] students=new Student[3];
        students[1]={"zhangsan",3};
        */
    }
}
